package robocup.component.tactics;

public class PassState
    extends AbstractState {

  // private ObjectStateSpeechAct ossa = new ObjectStateSpeechAct();

  /**
   * State that determines if passing is good
   */
  public PassState(
      final StateEvaluation parent) {

    super(parent);
    this.state = STATES.PASS;
  }

  /**
   * Precondition is set up checkPlayMode, defined in AbstractState.
   */
  @Override
  public boolean preCondition() {

    boolean simpleCheck = this.checkPlayMode() && this.checkMyBall();

    if (!simpleCheck) {
      return false;
    }
    final boolean b = this.getProphet().getScoreBenefit() < 0.70 && this.getProphet()
        .canPass();

    return b;
  }

  /**
   * The SuccessProbability of this state depends on the freeness of the player
   * and on the enemies that are on way to this player having the possibilty to
   * intercept the ball before reaching the teammate.
   */
  @Override
  protected double successProbability() {

    return 1.0;
  }

  /**
   * The success benefit depends on the position of the teammate, who intercepts
   * the pass.
   */
  @Override
  protected double successBenefit() {

    if (false && this.getProphet().getPassBenefit() > 0.1) {
      System.out
          .println(this.getWorld().getCycleAndPlayerString() + " PassingTo:" + this
              .getProphet().getPassTo());
      System.out
          .println("\t Pos:" + this.getProphet().getPassPoint() + " Ben:" + this
              .getProphet().getPassBenefit());
    }

    final double passBenefit = this.getProphet().getPassBenefit();
    return passBenefit;
  }

  @Override
  public void calculateMainAction() {

    // this.getProphet().printPassResults();
    this.mainAction = this.getProphet().getPassAction();
    //this.subStateString = this.getProphet().getPassTo() + "-" +this.getProphet().getPassPoint();
  }
}